視圖過濾的表示類與接口 (Presentation class vs Interface for View Filtering)


問題描述

視圖過濾的表示類與接口 (Presentation class vs Interface for View Filtering)

Why use a Presentation class instead of an Interface when filtering model properties for submission to View? 


參考解法

方法 1:

link textI think you are asking the following:

  

When passing a sub-set of properties   to a view, in order to limit the scope-of-knowledge, there are a number of   options.  Of those, one involves   copying the desired properties from   the model to an intermediate object (a   "presentation class" or a   "data-transfer object") and another   involves having the model implement an   interface and then passing that   interface to the view.

     

Why would you use the former as   opposed to the latter?

My answer would be that sometimes you don't have access to the model in order to make it implement that interface.  Other times you don't want to pollute your model with unecessary interfaces, for instance you can theoretically have a different interface for every view and that starts adding up.  

A hybrid alternative would be to use the adapter pattern to create a class that wraps your model, implements the interface, and delegates the interface calls to your model.  

There is no option that's really better than the rest, it all depends on your situation and your "style."

(by zsharpTalljoe)

參考文件

  1. Presentation class vs Interface for View Filtering (CC BY-SA 3.0/4.0)

#asp.net-mvc






相關問題

我返回集合的 Asp.net mvc 操作生成包含 system.linq.Enumerable 的 url,如何刪除它們 (My Asp.net mvc actions that return collection generate urls containing system.linq.Enumerable, how to remove them)

在 ASP.NET MVC3 中備份 MySQL 數據庫 (Backup MySQL database in ASP.NET MVC3)

jqgrid將參數傳遞給方法 (jqgrid passing parameter to method)

從局部視圖打開一個彈出窗口並重新加載父局部視圖 (open a popup from partial view and reload the parent partial view)

如何將 MVC 5 項目模板添加到 VS 2012? (How can I add the MVC 5 project template to VS 2012?)

如何避免使用 FirstOrDefault 未將對象引用設置為對象錯誤的實例? (How to avoid Object reference not set to instance of object error with FirstOrDefault?)

ASP.NET MVC:動作內的授權 - 建議的模式或者這是一種氣味? (ASP.NET MVC: Authorization inside an Action - Suggested Patterns or this is a smell?)

MVC 最佳實踐 | 您是否將鏈接構建到 Url Helper 中? (MVC Best Practices | Do you build your links into the Url Helper?)

返回包含 HTML 和 JavaScript 的 PartialView (Returning a PartialView with both HTML and JavaScript)

視圖過濾的表示類與接口 (Presentation class vs Interface for View Filtering)

C# MVC:MVC Html Helpers 與視圖中直接 HTML 的性能和優勢 (C# MVC: Performance and Advantages of MVC Html Helpers vs. Direct HTML in views)

在使用 azure 流量管理器和 azure 應用程序網關與 WAF 時實現國家級阻止 (Achieve country level blocking while using azure traffic manager and azure application gateway with WAF)







留言討論